package com.cl.activity;

import android.content.Intent;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;

import com.cl.safe.R;
import com.cl.ui.SettingItemView;

public class Setup2Activity extends BaseSetupActivity {
	protected static final String TAG = "Setup2Activity";
	private SettingItemView siv_bind_sim;
	private TelephonyManager tm;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_setup2);
		siv_bind_sim = (SettingItemView) findViewById(R.id.siv_bind_sim);
		tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
		//真实的手机序列
		String realSimSeria = tm.getSimSerialNumber();
		Log.i(TAG, "真实绑定的SIM卡序列"+realSimSeria);
		//获得绑定状态
		String simSeria = sp.getString("simSeria", "");
		Log.i(TAG, "绑定的SIM卡序列"+realSimSeria);
		if(TextUtils.isEmpty(simSeria)) {
			siv_bind_sim.setChecked(false);
		}else {
			siv_bind_sim.setChecked(true);
		}
				
		//SIM卡绑定点击事件
		siv_bind_sim.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Editor editor = sp.edit();
				if (siv_bind_sim.isChecked()) {//SIM卡没有绑定
					siv_bind_sim.setChecked(false);
					editor.putString("simSeria", "");
				} else {//SIM卡绑定
					siv_bind_sim.setChecked(true);
					String simSeria = tm.getSimSerialNumber();
					editor.putString("simSeria", simSeria);
					Log.i(TAG, "SIM卡序列"+simSeria);
				}
				editor.commit();
			}
		});
	}

	/**
	 * 进入下一页
	 * 
	 */
	@Override
	protected void showRight() {
		String simSeria = sp.getString("simSeria", "");
		if(TextUtils.isEmpty(simSeria))
			return;
		System.out.println("向右滑到了3");
		finish();
		Intent intent = new Intent(this, Setup3Activity.class);
		startActivity(intent);
		// 要求在finish()或者startActivity(intent);后面执行；
		overridePendingTransition(R.anim.tran_in, R.anim.tran_out);
	}

	/**
	 * 进入上一页
	 */
	@Override
	protected void showLeft() {
		System.out.println("向左滑到了1");
		finish();
		Intent intent = new Intent(this, Setup1Activity.class);
		startActivity(intent);
		// 要求在finish()或者startActivity(intent);后面执行；
		overridePendingTransition(R.anim.tran_pre_in, R.anim.tran_pre_out);
	}

	

}
